<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
export default {
  name: "Scroll",
  props: {
    probeType: {
        type: Number,
        default: 0
      }
  },
  data() {
    return {
      scroll: null      
    }
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,  // 监听div点击事件, click必须=true, button点击事件true, false都可以
      probeType: this.probeType,
      pullUpLoad: true
    })

    this.scroll.on('scroll', pos => {
      this.$emit('contentScroll', pos)
    })    
    this.scroll.on('pullingUp', () => {
      this.$emit('loadMore')
    })
    
  },
  methods: {
    scrollTo(x, y, time=500) {
      this.scroll && this.scroll.scrollTo(x, y, time);
    },
    refresh() {
      this.scroll && this.scroll.refresh()
    },
    finishPullUp() {
      this.scroll && this.scroll.finishPullUp()
    }
  }
};
</script>

<style scoped>
</style>
